package com.example.dagger2one.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.dagger2one.R;
import com.example.dagger2one.model.CommentsBean;
import com.example.dagger2one.model.UserBean;
import com.example.dagger2one.view.CommentsView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @作者: njb
 * @时间: 2019/7/22 19:10
 * @描述:
 */
public class CommentListActivity extends AppCompatActivity {
    @BindView(R.id.commentView)
    CommentsView commentsView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comment_list);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        commentsView.setList(getComments());
        commentsView.setOnItemClickListener(new CommentsView.onItemClickListener() {
            @Override
            public void onItemClick(int position, CommentsBean bean) {

            }
        });
        commentsView.notifyDataSetChanged();
    }

    /**
     * 生成评论列表
     * @return
     */
    public static List<CommentsBean> getComments() {
        List<CommentsBean> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            CommentsBean commentsBean = new CommentsBean();
            commentsBean.setCommentsId(i);
            commentsBean.setContent("zhe shi wo yong lai ce shi shu ru de wen ben nei rong " + i);
            if (i % 2 == 0) {
                UserBean replyUser = new UserBean();
                replyUser.setUserId(i + 30);
                replyUser.setUserName("用户" + replyUser.getUserId());
                commentsBean.setReplyUser(replyUser);
            }
            UserBean comUser = new UserBean();
            comUser.setUserId(i);
            comUser.setUserName("用户" + comUser.getUserId());

            commentsBean.setCommentsUser(comUser);

            list.add(commentsBean);
        }

        return list;
    }
}
